
/**		
 * 
 *	uk.co.lmfm.guppy.view.components.core.form.LabeledFormFieldLite
 *	
 *	@version 1.00 | Jan 15, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.guppy.view.components.core.form 
{
	import flash.events.FocusEvent;

	import com.bit101.components.InputText;

	import flash.events.Event;

	/**
	 * LabeledFormFieldLite
	 */
	public class LabeledFormFieldLite extends InputText 
	{
		//	----------------------------------------------------------------
		//	PUBLIC MEMBERS
		//	----------------------------------------------------------------

		public var label : String;

		//	----------------------------------------------------------------
		//	CONSTRUCTOR
		//	----------------------------------------------------------------

		public function LabeledFormFieldLite(label : String = "")
		{
			super();
			this.label = text = label;
			
			addEventListener(Event.CHANGE, onTextChanged);
			addEventListener(FocusEvent.FOCUS_IN, onFocusIn);			addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
		}

		//	----------------------------------------------------------------
		//	PRIVATE METHODS
		//	----------------------------------------------------------------

		private function clean() : void
		{
			text = text.replace(/\s+/g, ' ');
		}

		//	----------------------------------------------------------------
		//	EVENT HANDLERS
		//	----------------------------------------------------------------

		private function onFocusIn(event : FocusEvent) : void
		{
			clean();
			if(text == label) text = '';
		}

		private function onFocusOut(event : FocusEvent) : void
		{
			clean();
			if(text == '') text = label;
		}

		private function onTextChanged(event : Event) : void
		{
		}
	}
}
